import axios from 'axios'

class http {
  post(url, params) {
    return new Promise((resolve, rejects) => {
      axios({
        method: 'post',
        url:config.url+ url,
        data: params,
        headers:{
            'Accept': 'application/json',
            'token':localStorage.getItem('token')? localStorage.getItem('token') :""
        },
      }).then(res => {
        if (res.status === 200) {
          resolve(res.data)
        } else {
          rejects(res.data)
        }
      }).catch(err => {
        rejects(err)
        console.log('数据调用失败')
      })
    })
  };
  get(url, params) {
    return new Promise((resolve, rejects) => {
        // if(window.localStorage.getItem('has_token')){
        //     params.token = window.localStorage.getItem('has_token')
        // }
      axios({
        method: 'get',
        url:config.url+ url,
        params: params,
        headers: {
          'Accept':'application/json',
        },
        timeout: 15000
      }).then(res => {
        if (res.status === 200) {
          resolve(res.data)
        } else {
          rejects(res.data)
        }
      }).catch(err => {
        rejects(err)
      })
    })
  }
}

export default new http()
